#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_btnIniItems_clicked()
{
    ui->comboBox->clear();

    for(int i = 0; i < 20; i++)
    {
        ui->comboBox->addItem(QString("Item %1").arg(i));
    }
}


void Widget::on_btnIni2_clicked()
{
    QMap<QString, int> City_Zone;

    City_Zone.insert("北京",10);
    City_Zone.insert("上海",21);
    City_Zone.insert("天津",22);

    ui->comboBox2->clear();

    foreach(const QString &str, City_Zone.keys())
    {
        ui->comboBox2->addItem(str, City_Zone.value(str));
    }
}


void Widget::on_comboBox_currentTextChanged(const QString &arg1)
{
    ui->plainTextEdit->appendPlainText(arg1);
}


void Widget::on_comboBox2_currentIndexChanged(int index)
{
    Q_UNUSED(index);

    QString city = ui->comboBox2->currentText();
    QString zone = ui->comboBox2->currentData().toString();

    ui->plainTextEdit->appendPlainText(city+":区号= "+zone);
}

